<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/global.css" media="all"/>
</head>
<body>
<div class="form-filter-wrap" style="margin-top: 10px">
    <form class="layui-form form-inline page-form" onsubmit="return false" id="form">
        <div class="form-group">
            <div class="form-filter">
                <div class="form-inner">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="账号" type="text" name="username" lay-verify="required">
                    </div>
                </div>
                <div class="form-inner">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="密码" type="text" value="88888888" name="password"
                               lay-verify="required">
                    </div>
                </div>
                <div class="form-inner">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="用户名" type="text" maxlength="20"
                               name="nickname" lay-verify="required">
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="form-filter">
                <div class="form-inner">
                    <label class="layui-form-label">U聊账号</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="U聊账号" type="text" maxlength="50"
                               name="ul" lay-verify="required">
                    </div>
                </div>
                <div class="form-inner">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="邮箱" type="text" maxlength="50"
                               name="email" lay-verify="email">
                    </div>
                </div>
                <div class="form-inner">
                    <label class="layui-form-label">所属单位</label>
                    <div class="layui-input-inline">
                        <select multiple lay-omit name="branch" id="branch" lay-filter="branch" lay-search>
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="form-filter">
                <label class="layui-form-label">角色</label>
                <div class="checkbox" id="roles" style="line-height: 34px;">
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="form-filter">
                <div class="form-inner">
                    <label class="layui-form-label">审核人</label>
                    <div class="layui-input-inline">
                        <select lay-omit name="userId" id="userId" lay-filter="required">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-actions">
            <div class="row" align="center">
                <div class="col-md-12">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/my/roles/role.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer', 'laydate'], function () {
        var layer = layui.layer
            , form = layui.form;

        /*公司*/
        $.ajax({
            url: '/dropDown/getBranch',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                // 使用循环遍历，给下拉列表赋值
                $.each(data, function (index, value) {
                    $('#branch').append(new Option(value.value, value.key));// 下拉菜单里添加元素
                });
                form.render();//重新渲染 固定写法
            }
        })
            /*用户—审核人*/
            , $.ajax({
            url: '/dropDown/getUser',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                // 使用循环遍历，给下拉列表赋值
                $.each(data, function (index, value) {
                    $('#userId').append(new Option(value.value, value.key));// 下拉菜单里添加元素
                });
                form.render();//重新渲染 固定写法
            }
        });

        form.on('submit(formDemo)', function (data) {
            data.field.roleIds = getCheckedRoleIds();
            if (!$("#branch").val()) {
                layer.msg("请选择单位！");
                return false;
            }
            data.field.branch = $("#branch").val().toString();

            $.ajax({
                type: 'post',
                url: '/users',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data.field),
                success: function (data) {
                    layer.msg("保存成功！", {time: 1000, icon: 1}, function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                        parent.layer.close(index); //再执行关闭
                    });
                }
            })
            return false;
        });
    });

    initRoles();

</script>
</body>
</html>